﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace exp3
{
    public partial class Form1 : Form
    {
        PointF pictureLocation;

        float horizontalVelocity = 50;

        float verticalalVelocity = 25;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Width = 875;
            this.Height = 475;
            timer1.Enabled = true;
            timer1.Interval = 100;
            pictureLocation = pictureBox1.Location;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            pictureLocation.X += horizontalVelocity;

            pictureLocation.Y += verticalalVelocity;
            pictureBox1.Location = new Point((int)pictureLocation.X, (int)pictureLocation.Y);
            if (pictureBox1.Left <= 0) 
            { 
                horizontalVelocity = -horizontalVelocity;
            }
            if (pictureBox1.Right >= ClientSize.Width) { 
                horizontalVelocity = -horizontalVelocity; 
            }

            if (pictureBox1.Top <= 0) 
            { 
                verticalalVelocity = -verticalalVelocity; 
            }

            if (pictureBox1.Bottom >= ClientSize.Height)
            {
                verticalalVelocity = -verticalalVelocity;
            }

        }


        private void button1_Click(object sender, EventArgs e)
        {
            pictureLocation.X += horizontalVelocity;
            horizontalVelocity = 100;
            pictureLocation.Y += verticalalVelocity;
            verticalalVelocity = 50;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            pictureLocation.X += horizontalVelocity; 
            horizontalVelocity = 2;
            pictureLocation.Y += verticalalVelocity;
            verticalalVelocity = 1;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.ShowInTaskbar = false;
                this.Hide();
                
            }
        }

        private void 恢复ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.Visible == false)
                this.Visible = true;
        }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void contextMenuStrip1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            pictureLocation.X += horizontalVelocity;
            horizontalVelocity = 50/2f;
            pictureLocation.Y += verticalalVelocity; 
            verticalalVelocity = 25/2f;
        }
    }
}
